/*  1:   */ package org.jetbrains.rpc;
/*  2:   */ 
/*  3:   */

import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.util.BooleanFunction;
import com.intellij.util.Function;
import com.intellij.util.PairConsumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jsonProtocol.Request;
import org.jetbrains.jsonProtocol.RequestWithResponse;

import java.util.concurrent.atomic.AtomicInteger;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */ 
/* 14:   */ public abstract class MessageHandler<INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPONSE, ERROR_DETAILS>
/* 15:   */   implements MessageManager.Handler<Request, INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPONSE, ERROR_DETAILS>, ResultReader<SUCCESS_RESPONSE>, CommandSender<ERROR_DETAILS>
/* 16:   */ {
/* 17:17 */   private final AtomicInteger a = new AtomicInteger();
/* 18:   */   protected final MessageManager<Request, INCOMING, INCOMING_WITH_SEQ, SUCCESS_RESPONSE, ERROR_DETAILS> messageManager;
/* 19:   */   private final BooleanFunction<Request> b;
/* 20:   */   
/* 21:   */   protected MessageHandler(@NotNull BooleanFunction<Request> paramBooleanFunction)
/* 22:   */   {
/* 23:23 */     this.b = paramBooleanFunction;
/* 24:24 */     this.messageManager = new MessageManager(this);
/* 25:   */   }
/* 26:   */   
/* 27:   */   public void cancelWaitingRequests()
/* 28:   */   {
/* 29:28 */     this.messageManager.cancelWaitingRequests();
/* 30:   */   }
/* 31:   */   
/* 32:   */   public void closed()
/* 33:   */   {
/* 34:32 */     this.messageManager.closed();
/* 35:   */   }
/* 36:   */   
/* 37:   */   public boolean write(@NotNull Request paramRequest)
/* 38:   */   {
/* 39:37 */     if (paramRequest == null) {
/* 40:37 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/rpc/MessageHandler", "write" }));
/* 41:   */     }
/* 42:37 */     return this.b.fun(paramRequest);
/* 43:   */   }
/* 44:   */   
/* 45:   */   public final int getUpdatedSequence(Request paramRequest)
/* 46:   */   {
/* 47:42 */     int i = this.a.incrementAndGet();
/* 48:43 */     paramRequest.finalize(i);
/* 49:44 */     return i;
/* 50:   */   }
/* 51:   */   
/* 52:   */   public final ActionCallback send(Request paramRequest)
/* 53:   */   {
/* 54:49 */     CommandCallbackWithoutResponse localCommandCallbackWithoutResponse = new CommandCallbackWithoutResponse();
/* 55:50 */     this.messageManager.send(paramRequest, localCommandCallbackWithoutResponse);
/* 56:51 */     return localCommandCallbackWithoutResponse.callback;
/* 57:   */   }
/* 58:   */   
/* 59:   */   public final <RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull RequestWithResponse paramRequestWithResponse, @NotNull Function<RESULT, TRANSFORMED_RESULT> paramFunction)
/* 60:   */   {
/* 61:56 */     if (paramRequestWithResponse == null) {
/* 62:56 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/rpc/MessageHandler", "send" }));
/* 63:   */     }
/* 64:56 */     if (paramFunction == null) {
/* 65:56 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/rpc/MessageHandler", "send" }));
/* 66:   */     }
/* 67:56 */     return send(paramRequestWithResponse, paramFunction, null);
/* 68:   */   }
/* 69:   */   
/* 70:   */   public final <RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull RequestWithResponse paramRequestWithResponse, @NotNull Function<RESULT, TRANSFORMED_RESULT> paramFunction, @Nullable ErrorConsumer<AsyncResult<TRANSFORMED_RESULT>, ERROR_DETAILS> paramErrorConsumer)
/* 71:   */   {
/* 72:63 */     if (paramRequestWithResponse == null) {
/* 73:63 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/rpc/MessageHandler", "send" }));
/* 74:   */     }
/* 75:63 */     if (paramFunction == null) {
/* 76:63 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/rpc/MessageHandler", "send" }));
/* 77:   */     }
/* 78:63 */     CommandCallbackWithResponse localCommandCallbackWithResponse = new CommandCallbackWithResponse(paramRequestWithResponse.getMethodName(), paramFunction, paramErrorConsumer);
/* 79:   */     
/* 80:65 */     this.messageManager.send(paramRequestWithResponse, localCommandCallbackWithResponse);
/* 81:66 */     return (AsyncResult)localCommandCallbackWithResponse.callback;
/* 82:   */   }
/* 83:   */   
/* 84:   */   public final <RESULT, TRANSFORMED_RESULT> void send(@NotNull AsyncResult<TRANSFORMED_RESULT> paramAsyncResult, @NotNull RequestWithResponse paramRequestWithResponse, @NotNull Function<RESULT, TRANSFORMED_RESULT> paramFunction)
/* 85:   */   {
/* 86:73 */     if (paramAsyncResult == null) {
/* 87:73 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/rpc/MessageHandler", "send" }));
/* 88:   */     }
/* 89:73 */     if (paramRequestWithResponse == null) {
/* 90:73 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/rpc/MessageHandler", "send" }));
/* 91:   */     }
/* 92:73 */     if (paramFunction == null) {
/* 93:73 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "2", "org/jetbrains/rpc/MessageHandler", "send" }));
/* 94:   */     }
/* 95:73 */     this.messageManager.send(paramRequestWithResponse, new CommandCallbackWithResponse(paramAsyncResult, paramRequestWithResponse.getMethodName(), paramFunction, null));
/* 96:   */   }
/* 97:   */   
/* 98:   */   public final <RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull RequestWithResponse paramRequestWithResponse, @NotNull PairConsumer<RESULT, AsyncResult<TRANSFORMED_RESULT>> paramPairConsumer)
/* 99:   */   {
/* :0:79 */     if (paramRequestWithResponse == null) {
/* :1:79 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/rpc/MessageHandler", "send" }));
/* :2:   */     }
/* :3:79 */     if (paramPairConsumer == null) {
/* :4:79 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/rpc/MessageHandler", "send" }));
/* :5:   */     }
/* :6:79 */     return send(new AsyncResult(), paramRequestWithResponse, paramPairConsumer);
/* :7:   */   }
/* :8:   */   
/* :9:   */   public final <RESULT, TRANSFORMED_RESULT> AsyncResult<TRANSFORMED_RESULT> send(@NotNull AsyncResult<TRANSFORMED_RESULT> paramAsyncResult, @NotNull RequestWithResponse paramRequestWithResponse, @NotNull PairConsumer<RESULT, AsyncResult<TRANSFORMED_RESULT>> paramPairConsumer)
/* ;0:   */   {
/* ;1:86 */     if (paramAsyncResult == null) {
/* ;2:86 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/rpc/MessageHandler", "send" }));
/* ;3:   */     }
/* ;4:86 */     if (paramRequestWithResponse == null) {
/* ;5:86 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/rpc/MessageHandler", "send" }));
/* ;6:   */     }
/* ;7:86 */     if (paramPairConsumer == null) {
/* ;8:86 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "2", "org/jetbrains/rpc/MessageHandler", "send" }));
/* ;9:   */     }
/* <0:86 */     this.messageManager.send(paramRequestWithResponse, new NestedCommandCallbackWithResponse(paramAsyncResult, paramRequestWithResponse.getMethodName(), paramPairConsumer));
/* <1:87 */     return paramAsyncResult;
/* <2:   */   }
/* <3:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.rpc.MessageHandler

 * JD-Core Version:    0.7.0.1

 */